package org.jeecg.modules.jxc.goodstype.controller;

import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.jxc.goodstype.entity.Goods;
import org.jeecg.modules.jxc.goodstype.entity.JxcGoodsType;
import org.jeecg.modules.jxc.goodstype.service.GoodsService;
import org.jeecg.modules.jxc.homepage.entity.JxcGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @description:
 * @company: yaorange
 * @author: Mr.Yu
 * @version: 1.0
 * @create: 2021-12-22 10:10:32
 */

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;


    /**
     * 根据商品类别id查询商品
     * @param typeId
     * @return
     */
    @GetMapping("/goodsList/{typeId}")
    public ResponseEntity<?> goodsList(@PathVariable("typeId")String typeId,
                                       @RequestParam(value = "good",required = false)String good){
        if (StringUtils.isNotBlank(typeId)){
            List<Goods> list=goodsService.selectList(typeId,good);
            return ResponseEntity.ok(list);
        }
        return null;
    }

    /**
     * 查询
     * @return
     */
    @GetMapping("/goodsType")
    public ResponseEntity<List> goodsTypeList(){
        List<JxcGoodsType> list= goodsService.selectTypeList();
        return ResponseEntity.ok(list);
    }

    /**
     * 新增
     * @param goods
     * @return
     */
    @PostMapping("/add")
    public ResponseEntity<?> add(@RequestBody Goods goods){
            goodsService.add(goods);
        return ResponseEntity.ok().build();
    }

    /**
     * 根据id查询单个商品
     * @param id
     * @return
     */
    @GetMapping("/selectById/{id}")
    public ResponseEntity<?> getById(@PathVariable String id){
        Goods goods=goodsService.selectById(id);
        return ResponseEntity.ok(goods);
    }

    /**
     * 修改
     * @param goods
     * @return
     */
    @PutMapping("/putGoods")
    public ResponseEntity<?> putById(@RequestBody Goods goods){
        goodsService.updateById(goods);
        return ResponseEntity.ok().build();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById/{id}")
    public ResponseEntity<?> deleteById(@PathVariable String id){
        goodsService.deleteById(id);
        return ResponseEntity.ok().build();
    }
}
